const fs = require("fs");
const path = require("path");

// const fullFileName = path.resolve(__dirname, "json", "a.json");

// fs.readFile(fullFileName, (err, data) => {
//   if (err) return console.error(err);
//   console.log(data.toString());
// });

function getFileContent(fileName) {
  console.log(fileName, "in getFile");
  return new Promise((resolve, reject) => {
    const fullFileName = path.resolve(__dirname, "json", fileName);
    fs.readFile(fullFileName, (err, data) => {
      if (err) return reject(err);
      //   callback(JSON.parse(data.toString()));
      resolve(JSON.parse(data.toString()));
      console.log(data.toString());
    });
  });
}
getFileContent("a.json")
  .then((a) => getFileContent(a.next))
  .then((b) => getFileContent(b.next));

// callback hell
// async await
